package vn.edu.saigontech.ncms.web.system;

import vn.edu.saigontech.ncms.util.Checker;
import vn.edu.saigontech.ncms.util.DateUtil;
import vn.edu.saigontech.ncms.web.AbstractValidator;

@SuppressWarnings("serial")
public class ValidateDayOffAction extends AbstractValidator {
	private String date;
	private String endDate;
	private String comment;
	
	@Override
	public String check() {
		if(Checker.isEmpty(this.date)) {
			this.sendKeyError("validator.required", "fromDate");
		}
		if(!Checker.isDate(this.date, this.i18n("format.date"))) {
			this.sendKeyError("validator.mask", "fromDate", "format.date");
		}
		if(Checker.isEmpty(this.endDate)) {
			this.sendKeyError("validator.required", "toDate");
		}
		if(!Checker.isDate(this.endDate, this.i18n("format.date"))) {
			this.sendKeyError("validator.mask", "toDate", "format.date");
		}
		if(DateUtil.fromString(this.date, this.i18n("format.date")).after(DateUtil.fromString(this.endDate, this.i18n("format.date")))) {
			this.sendKeyError("validator.greater", "toDate", "fromDate");
		}
		if(Checker.isEmpty(this.comment)) {
			this.sendKeyError("validator.required", "name");
		}
		return this.toSuccess();
	}

	public String getDate() {
		return date;
	}

	public void setDate(String date) {
		this.date = date;
	}

	public String getEndDate() {
		return endDate;
	}

	public void setEndDate(String endDate) {
		this.endDate = endDate;
	}

	public String getComment() {
		return comment;
	}

	public void setComment(String comment) {
		this.comment = comment;
	}
}
